﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraLayout.Utils;
using NetROS.Tiers.Entities;

namespace NetRosApp.FinPart.Views.PutniNalogView
{
    public partial class PutniNalogIsplataUpit : DevExpress.XtraEditors.XtraForm
    {
        public PutniNalogIsplataUpit()
        {
            InitializeComponent();
        }
        public PutniNalogIsplataUpit(TList<Blagajna> blagajnaViews,DateTime? datumuplate)
        {
            InitializeComponent();
            SetBlagajne(blagajnaViews);
            
            dateEdit1.EditValue = datumuplate?? DateTime.Today;
            layoutControlItem5.Visibility = LayoutVisibility.Never;
            layoutControlItem6.Visibility = LayoutVisibility.Never;
         //   lookUpEdit1.ItemIndex = 0;
        }

          public PutniNalogIsplataUpit(TList<Blagajna> blagajnaViews)
        {
            InitializeComponent();
            SetBlagajne(blagajnaViews);
            dateEdit1.EditValue = DateTime.Today;
              layoutControlItem5.Visibility = LayoutVisibility.Never;
              layoutControlItem6.Visibility = LayoutVisibility.Never;
             
        }

              public PutniNalogIsplataUpit(TList<Blagajna> blagajnaViews,bool selection)
        {
            InitializeComponent();
            SetBlagajne(blagajnaViews);
            dateEdit1.EditValue = DateTime.Today;
              layoutControlItem5.Visibility = LayoutVisibility.Always;
                  layoutControlItem6.Visibility = LayoutVisibility.Always;
             
        }


        public void SetBlagajne(TList<Blagajna> blagajnaViews)
        {
            bsBlagajna.SuspendBinding();
            bsBlagajna.DataSource = blagajnaViews;
            bsBlagajna.ResumeBinding();
            //lookUpEdit1.Properties.GetDataSourceRowIndex();

            if (blagajnaViews.Count >0)
            {
                //lookUpEdit1.EditValue = lookUpEdit1.Properties.GetDataSourceValue(lookUpEdit1.Properties.ValueMember,
                //                                                                  lookUpEdit1.Properties.
                //                                                                      GetDataSourceRowIndex("ID", blagajnaViews[0].ID));
                 Blagajna blagajna =  blagajnaViews.Find("Naziv", "Blagajna PN");
              if (blagajna != null)
              {
                  lookUpEdit1.EditValue = blagajna.ID;
              }
              else
              {
                  lookUpEdit1.EditValue = blagajnaViews[0].ID;
              }
            }


        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Yes;
            Close();
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }
    }
}